export function init(O, nodeArr, linkArr) {
  let $ = go.GraphObject.make;
  if (O.myDiagram) {
    O.myDiagram.div = null
  }
  let _O = O
  O.myDiagram =
    $(go.Diagram, "myDiagramDiv",
      {
        initialAutoScale: go.Diagram.Uniform,
        contentAlignment: go.Spot.Center,
        layout:
          $(go.ForceDirectedLayout,
            {maxIterations: 400, defaultSpringLength: 30, defaultElectricalCharge: 100})
      });

  O.myDiagram.nodeTemplate =
    $(go.Node, "Horizontal",
      $(go.Picture,
        {
          margin: 5,
          width: 30,
          height: 30,
          background: "pink"
        }, new go.Binding("source", 'img')),
      $(go.Shape, "Rectangle", {fill: "lightgray"}
      ),
      $(go.Panel, "Table",
        $(go.RowColumnDefinition,
          {column: 0, alignment: go.Spot.Left}),
        $(go.RowColumnDefinition,
          {column: 2, alignment: go.Spot.Right}),
        $(go.TextBlock,  // the node title
          {
            column: 0, row: 0, columnSpan: 3, alignment: go.Spot.Center,
            font: "bold 10pt sans-serif", margin: new go.Margin(4, 2)
          },
          new go.Binding("text", "key")),
        $(go.Panel, "Horizontal",
          {column: 0, row: 1},
          $(go.Shape,  // the "A" port
            {width: 6, height: 6, portId: "A", toSpot: go.Spot.Left}),
          $(go.TextBlock, "A")  // "A" port label
        ),
        $(go.Panel, "Horizontal",
          {column: 0, row: 2},
          $(go.Shape,  // the "B" port
            {width: 6, height: 6, portId: "B", toSpot: go.Spot.Left}),
          $(go.TextBlock, "B")  // "B" port label
        ),
        $(go.Panel, "Horizontal",
          {column: 2, row: 1, rowSpan: 2},
          $(go.TextBlock, "Out"),  // "Out" port label
          $(go.Shape,  // the "Out" port
            {width: 6, height: 6, portId: "Out", fromSpot: go.Spot.Right})
        )
      )
    );

  O.myDiagram.linkTemplate =
    $(go.Link,
      {routing: go.Link.Orthogonal, corner: 3},
      $(go.Shape),
      $(go.Shape, {toArrow: "Standard"})
    );

  O.myDiagram.layout = $(go.LayeredDigraphLayout, {columnSpacing: 10});

  O.myDiagram.model =
    $(go.GraphLinksModel,
      {
        linkFromPortIdProperty: "fromPort",  // required information:
        linkToPortIdProperty: "toPort",      // identifies data property names
        nodeDataArray: [
          {key: "Add1",img:O.switchImg},
          {key: "Add2",img:O.switchImg},
          {key: "Subtract1",img:O.switchImg}
        ],
        linkDataArray: [
          {from: "Add1", fromPort: "Out", to: "Subtract1", toPort: "A"},
          {from: "Add2", fromPort: "Out", to: "Subtract1", toPort: "B"}
        ]
      })
}
